/* REXX _clv_watch.zrx by the reverend (build 51) */ /*- built by rev-builder version 1.1 on 02 Jan 2003 at 11:11:21 -*/ /*- ------------------------------------------------------------------------ -*/ /*- Copyright (C) 2001 Ron Wilson -*/ /*- -*/ /*- This script is free, and can be modified for your personal use, but you -*/ /*- cannot copy or distribute this script or any derivative work based upon -*/ /*- this script without the express permission of the author. Your use of -*/ /*- this script is governed by the terms of the REV-LICENSE. -*/ /*- -*/ /*- This program is provided to you WITHOUT ANY WARRANTY, even the implied -*/ /*- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -*/ /*- REV-LICENSE for more details. -*/ /*- -*/ /*- A copy of the REV-LICENSE is available at: -*/ /*- http://thereverend.coastgames.com/tradewars/rev-license.html -*/ /*- ------------------------------------------------------------------------ -*/ /* rev. 0 - initial release */ call zocsynctime 500 globals=_setglobals() call on halt name _halt call zockeyboard "LOCK" timeout=120 call zoctimeout timeout if \_pcheck("Command [;Citadel command") then call _quit "please start at the command prompt or the citadel prompt" interval=_askint("enter watch interval (sec)", 10, "c") timeleft=interval call _clvinit call _onlineinit do FOREVER if timeleft>0 then do call zoctimeout timeleft call time "R" ans=zocwaitmux("INACTIVITY WARNING", "(?=Help)? :", "STATUS") end /*if*/ else ans=640 call zoctimeout timeout select when ans=0 then call zocsend "#" when ans=1 then call zocwrite _ansi("bt;fgr")||"< _clv_watch ("||max(trunc((timeleft-time("E"))*10)/10,0)||") > "||_ansi("fmg") when ans=2 then call zocsend "'REV-SCRIPT: _clv_watch running...^M" when ans=640 then do call _clvget call _onlineget if _clvreport() | _onlinereport() then call _beep "alert.wav" call zocsend "d" end /*when*/ otherwise nop end /*select*/ if ans<640 then timeleft=timeleft-time("E") else timeleft=interval end /*do*/ exit /*** THE REVEREND'S TW LIBRARY FOR ZOC/REXX ***/ /** _setglobals v.3 **/ _setglobals: procedure expose _verbose _monthdays _monthnames _baseday. (globals) _verbose=0 _monthdays="31;28;31;30;31;30;31;31;30;31;30;31" _monthnames="jan;feb;mar;apr;may;jun;jul;aug;sep;oct;nov;dec" _baseday.2000=730118 _baseday.2001=_baseday.2000+365+1 _baseday.2002=_baseday.2001+365 _baseday.2003=_baseday.2002+365 _baseday.2004=_baseday.2003+365 _baseday.2005=_baseday.2004+365+1 _baseday.2006=_baseday.2005+365 _baseday.2007=_baseday.2006+365 _baseday.2008=_baseday.2007+365 rslt="_g. _s. _p. _d. _v. _f. _m. _q. " rslt=rslt||"_ef. _es. _et. _ep. " rslt=rslt||"_path. _dist. _dtomsl. _dfrmsl. " rslt=rslt||"_bg. _nwi. _od. _sv. _pv. _bust. _vs. _vn. " rslt=rslt||"_olist1. _olist2. _clvlist1. _clvlist2. " rslt=rslt||"_verbose _monthdays _monthnames _baseday. " rslt=rslt||"globals reconnect scriptname lra " if arg(1,"E") then rslt=rslt||arg(1) rslt=_space(rslt) return rslt /** _halt v.3 **/ _halt: procedure expose (globals) call off halt call zocwriteln "^[[1;33m< user abort >^[[0m " exit return /** _pcheck v.4 **/ _pcheck: procedure expose (globals) pc1=arg(1) pc2=zocgetscreen(0, zocgetinfo("CURSOR-Y"), zocgetinfo("CURSOR-X")) rslt=0 do i=1 to _dwords(pc1,";") if _instr(_dword(pc1,i,";"),pc2,"cs") then rslt=1 end /*do*/ return rslt /** _quit v.7 **/ _quit: procedure expose (globals) lcpy=1 arg1="" do i=1 to 2 /* manage arguments */ select when arg(i,"E") & lower(arg(i))="nocopy" then lcpy=0 when arg(i,"E") & arg1="" then arg1=arg(i) otherwise nop end /*select*/ end /*do*/ line=zocgetscreen(0, zocgetinfo("CURSOR-Y"), zocgetinfo("CURSOR-X")) select /* define message */ when lcpy & arg1="" then msg="^[[1;32m< end script >^[[0m^M^J"||line when \lcpy & arg1="" then msg="^[[1;32m< end script >^[[0m " when lcpy then msg="^[[1;32m^M^J< end script: "||arg1||" >^[[0m^M^J"||line when \lcpy then msg="^[[1;32m^M^J< end script: "||arg1||" >^[[0m " otherwise nop end /*select*/ call zocwrite msg select /* choose a beep */ when lower(arg1)="script cancelled by user." then call _beep "cancel.wav" otherwise call _beep "quit.wav" end /*select*/ exit return 1 /** _askint v.2 **/ _askint: procedure expose (globals) do i=1 to 3 select when i=1 & arg(i,"E") then msg=arg(i) when i=1 then msg="enter an integer:" when i=2 & arg(i,"E") then default=arg(i) when i=2 then default="" when i=3 & arg(i,"E") then cflag=min(verify(lower(arg(i)),"c","M"),1) when i=3 then cflag=0 otherwise nop end /*select*/ end /*do*/ rslt=strip(zocask(msg, default)) do while _stripint(rslt)\=rslt | rslt="" default=rslt||" [please enter an integer or ESC to cancel.]" if rslt="##CANCEL##" then leave else rslt=strip(zocask(msg, default)) end /*do*/ if cflag & rslt="##CANCEL##" then call _quit "script cancelled by user.", "nocopy" return rslt /** _clvinit v.1 **/ _clvinit: procedure expose (globals) _clvlist1.="" _clvlist1.0=0 call _clvget return /** _onlineinit v.2 **/ _onlineinit: procedure expose (globals) _olist1.="" _olist1.0=0 call _onlineget return /** _ansi v.3 **/ _ansi: procedure expose (globals) rslt="0" do i=1 to _dwords(arg(1),";") w=_dword(arg(1),i,";") select when w="dl" then rslt=rslt||";"||0 /* dull */ when w="bt" then rslt=rslt||";"||1 /* bright */ when w="ul" then rslt=rslt||";"||4 /* underlined */ when w="blk" then rslt=rslt||";"||5 /* blinking */ when w="fbk" then rslt=rslt||";"||30 /* black foreground */ when w="frd" then rslt=rslt||";"||31 /* red foreground */ when w="fgr" then rslt=rslt||";"||32 /* green foreground */ when w="fye" then rslt=rslt||";"||33 /* yellow foreground */ when w="fbl" then rslt=rslt||";"||34 /* blue foreground */ when w="fmg" then rslt=rslt||";"||35 /* magenta foreground */ when w="fcy" then rslt=rslt||";"||36 /* cyan foreground */ when w="fwh" then rslt=rslt||";"||37 /* white foreground */ when w="bbk" then rslt=rslt||";"||40 /* black background */ when w="brd" then rslt=rslt||";"||41 /* red background */ when w="bgr" then rslt=rslt||";"||42 /* green background */ when w="bye" then rslt=rslt||";"||43 /* yellow background */ when w="bbl" then rslt=rslt||";"||44 /* blue background */ when w="bmg" then rslt=rslt||";"||45 /* magenta background */ when w="bcy" then rslt=rslt||";"||46 /* cyan background */ when w="bwh" then rslt=rslt||";"||47 /* white background */ otherwise nop end /*select*/ end /*do*/ rslt="^[["||rslt||"m" return rslt /** _clvget v.2 **/ _clvget: procedure expose (globals) buflen=10*1024 call zocreceivebuf buflen call zocsend "clvq" if zocwait("")=640 then call _error "timeout" if zocwait("Trader Rankings :")=640 then call _error "timeout" if zocwaitmux("Command [", "Citadel command")=640 then call _error "timeout" buff=translate(zocreceivebuf(0)," ",d2c(10)||d2c(0)) if length(buff)=buflen then call _error "buffer overflow" _clvlist2.="" do i=1 to _clvlist1.0 _clvlist2.i=_clvlist1.i end /*do*/ _clvlist2.0=_clvlist1.0 _clvlist1.="" _clvlist1.0=0 i=pos("-- -- --",buff) if i>0 then i=pos(d2c(13),buff,i)+1 j=pos(d2c(13),buff,i) c=0 do while i>1 & j>0 parse value substr(buff,i,j-i) with num exp aln corp line num=_stripint(num) exp=_stripint(exp) aln=_stripint(aln) if num="" | exp="" | aln="" then i=0 else do if corp="**" then corp=0 name=strip(left(line,30)) ship=strip(substr(line,32)) c=c+1 _clvlist1.c=name||";"||exp||";"||aln||";"||corp||";"||ship i=j+1 j=pos(d2c(13),buff,i) end /*else*/ end /*do*/ _clvlist1.0=c return /** _onlineget v.7 **/ _onlineget: procedure expose (globals) if _g.RED.0="_G.RED.0" then call _load_rank_names bufsize=5*1024 call zocreceivebuf bufsize blanklines=0 if _sendwait("#"," Who's Playin")=640 then call _error "timeout" do while blanklines<2 if zocwaitmux("e","a","^M")=640 then call _error "timeout" line=strip(_lastline()) if line="" then blanklines=blanklines+1 end /*do*/ buff=translate(zocreceivebuf(0)," ",d2c(10)||d2c(0)) if length(buff)=bufsize then call _error "buffer overflow in _onlineget" _olist2.="" do i=1 to _olist1.0 _olist2.i=_olist1.i end /*do*/ _olist2.0=_olist1.0 _olist1.="" _olist1.0=0 i=max(pos("Who's Playing",buff),1) i=pos(d2c(13),buff,i)+1 c=0 do while i>1 j=pos(d2c(13),buff,i) if j>0 then line=strip(substr(buff,i,j-i)) i=j+1 if line\="" then do c=c+1 line.c=line end /*if*/ end /*do*/ do i=1 to c /* split rank and name */ do j=1 to 23 k=word(_g.BLUE.0,j) if left(line.i,length(_g.BLUE.k))=_g.BLUE.k then leave end /*do*/ if j<24 then do rank.i=k-1 name.i=substr(line.i,length(_g.BLUE.k)+2) end /*if*/ else do do j=1 to 22 k=word(_g.RED.0,j) if left(line.i,length(_g.RED.k))=_g.RED.k then leave end /*do*/ if j<23 then do rank.i=-k name.i=substr(line.i,length(_g.RED.k)+2) end /*if*/ else k=0 end /*else*/ /* split name and corp */ parse value reverse(name.i) with temp1 "]" num "[" temp2 corp.i=0 if num="" then , if _stripint(num)=num & temp1="" & strip(temp2)\="" then do corp.i=reverse(num) name.i=reverse(substr(reverse(name.i),4+length(num))) end /*if*/ _olist1.i=name.i||";"||corp.i||";"||rank.i end /*do*/ _olist1.0=c return /** _clvreport v.3 **/ _clvreport: procedure expose (globals) msg.="" if _verbose then msg.1="REV-SCRIPT: clv update^M" else msg.1="" exptag="EXP" alntag="ALN" shiptag="SHIP" corptag="CORP" deltag="PLAYER DELETED" explimit=5 alnlimit=5 do i=1 to _clvlist1.0 found=0 do j=1 to _clvlist2.0 if _dword(_clvlist1.i,1,";")=_dword(_clvlist2.j,1,";") then do found=1 dexp=_dword(_clvlist1.i,2,";")-_dword(_clvlist2.j,2,";") select when dexp=0 then nop when dexp>explimit then msg.2=msg.2||" "||exptag||": "||_dword(_clvlist1.i,1,";")||" gained "||dexp||" exp.^M" when dexp<-explimit then msg.2=msg.2||" "||exptag||": "||_dword(_clvlist1.i,1,";")||" lost "||abs(dexp)||" exp.^M" otherwise _clvlist1.i=_dword(_clvlist1.i,1,";")||";"||_dword(_clvlist2.j,2,";")||";"||_dword(_clvlist1.i,3,";")||";"||_dword(_clvlist1.i,4,";")||";"||_dword(_clvlist1.i,5,";") end /*select*/ daln=_dword(_clvlist1.i,3,";")-_dword(_clvlist2.j,3,";") select when daln=0 then nop when daln>alnlimit then msg.2=msg.2||" "||alntag||": "||_dword(_clvlist1.i,1,";")||" gained "||daln||" align.^M" when daln<-alnlimit then msg.2=msg.2||" "||alntag||": "||_dword(_clvlist1.i,1,";")||" lost "||abs(daln)||" align.^M" otherwise _clvlist1.i=_dword(_clvlist1.i,1,";")||";"||_dword(_clvlist1.i,2,";")||";"||_dword(_clvlist2.j,3,";")||";"||_dword(_clvlist1.i,4,";")||";"||_dword(_clvlist1.i,5,";") end /*select*/ if _dword(_clvlist1.i,4,";")\=_dword(_clvlist2.j,4,";") then do select when _dword(_clvlist1.i,4,";")=0 then msg.2=msg.2||" "||corptag||": "||_dword(_clvlist1.i,1,";")||" left corp "||_dword(_clvlist2.j,4,";")||".^M" when _dword(_clvlist2.j,4,";")=0 then msg.2=msg.2||" "||corptag||": "||_dword(_clvlist1.i,1,";")||" joined corp "||_dword(_clvlist1.i,4,";")||".^M" otherwise msg.2=msg.2||" "||corptag||": "||_dword(_clvlist1.i,1,";")||" switched from corp "||_dword(_clvlist2.j,4,";")||" to "||_dword(_clvlist1.i,4,";")||".^M" end /*select*/ end /*if*/ if _dword(_clvlist1.i,5,";")\=_dword(_clvlist2.j,5,";") then msg.2=msg.2||" "||shiptag||": "||_dword(_clvlist1.i,1,";")||" is now in a "||_dword(_clvlist1.i,5,";")||".^M" leave end /*if*/ end /*do*/ if \found then msg.2=msg.2||" "||deltag||": "||_dword(_clvlist1.i,1,";")||"^M" end /*do*/ if msg.2="" then rslt=0 else do rslt=1 call zocsend "'^M"||msg.1||msg.2||"^M" end /*else*/ return rslt /** _onlinereport v.3 **/ _onlinereport: procedure expose (globals) msg.="" if _verbose then msg.1="REV-SCRIPT: online update^M" else msg.1="" newtag="IN" gonetag="OUT" do i=1 to _olist1.0 found=0 do j=1 to _olist2.0 if _dword(_olist1.i,1,";")=_dword(_olist2.j,1,";") then do found=1 leave end /*if*/ end /*do*/ if \found then msg.2=msg.2||" "||newtag||": "||_dword(_olist1.i,1,";")||"^M" end /*do*/ do i=1 to _olist2.0 found=0 do j=1 to _olist1.0 if _dword(_olist2.i,1,";")=_dword(_olist1.j,1,";") then do found=1 leave end /*if*/ end /*do*/ if \found then msg.3=msg.3||" "||gonetag||": "||_dword(_olist2.i,1,";")||"^M" end /*do*/ rslt=1 select when msg.2="" & msg.3="" then rslt=0 when msg.2\="" & msg.3\="" then call zocsend "'^M"||msg.1||msg.2||msg.3||"^M" when msg.3="" then call zocsend "'^M"||msg.1||msg.2||"^M" when msg.2="" then call zocsend "'^M"||msg.1||msg.3||"^M" otherwise rslt=0 end /*select*/ return rslt /** _beep v.2 **/ _beep: procedure expose (globals) select when arg(1,"O") then call zocwrite d2c(7) when _fileexists(arg(1)) then call zocplaysound arg(1) otherwise call zocwrite d2c(7) end /*select*/ return /** _space v.1 **/ _space: procedure expose (globals) str=strip(arg(1)) if arg(2,"E") then n=arg(2); else n=1 if arg(3,"E") then pad=arg(3); else pad=" " rslt=word(str,1) do i=2 to words(str) rslt=rslt||copies(pad,n)||word(str,i) end /*do*/ return rslt /** _dwords v.2 **/ _dwords: procedure expose (globals) rslt=words(translate(arg(1),arg(2)||" "," "||arg(2))) return rslt /** _instr v.3 **/ _instr: procedure expose (globals) fnd=arg(1) str=arg(2) if lower(arg(3))\="cs" then do fnd=lower(fnd) str=lower(str) end /*if*/ if arg(1,"E") & arg(2,"E") & pos(fnd,str)>0 then rslt=1 else rslt=0 return rslt /** _dword v.2 **/ _dword: procedure expose (globals) rslt=translate(word(translate(arg(1),arg(3)||" "," "||arg(3)),arg(2))," "||arg(3),arg(3)||" ") return rslt /** _stripint v.4 **/ _stripint: procedure expose (globals) mask=_space(translate(arg(1)," ","-0123456789"," "),0) rslt=_space(translate(arg(1)," ",mask," "),0) if left(rslt,1)="-" then rslt="-"||_space(translate(rslt," ","-"),0) else rslt=_space(translate(rslt," ","-"),0) if \datatype(rslt,"W") then rslt="" return rslt /** _error v.7 **/ _error: procedure expose (globals) call off halt if zocgetinfo("CURSOR-X")>0 then call zocwriteln call zocwrite _ansi("bt;frd")||"< script error" if arg(1,"E") then call zocwrite ": "||arg(1) call zocwriteln " >" call zocwriteln _ansi("bt;fye")||"< if this is a serious problem, email me at: the.reverend@coastgames.com > " call zocwriteln "< ZOC VERSION '"||zocgetinfo("VERSION")||"', OS '"||zocgetinfo("OSYS")||"', LOCATION '"||zocgetinfo("CONNECTEDTO")||"' >" if arg(2,"E") then call zocwriteln _ansi("bt;fgr")||"< "||arg(2)||" >" call zocwrite _ansi() call _beep "error.wav" if reconnect=1 & arg(1)="timeout" then do /* call zocdisconnect */ call zocwriteln _ansi("bt;fwh")||"< ATTEMPTING TO RECONNECT >" call zocdostring "^RUN=_connect.zrx sn="||scriptname end /*if*/ exit /** _load_rank_names v.1 **/ _load_rank_names: procedure expose (globals) _g.RED.0="12 10 7 8 9 11 22 13 1 2 3 15 4 5 6 14 21 17 18 19 20 16" _g.RED.1="Nuisance 3rd Class" _g.RED.2="Nuisance 2nd Class" _g.RED.3="Nuisance 1st Class" _g.RED.4="Menace 3rd Class" _g.RED.5="Menace 2nd Class" _g.RED.6="Menace 1st Class" _g.RED.7="Smuggler 3rd Class" _g.RED.8="Smuggler 2nd Class" _g.RED.9="Smuggler 1st Class" _g.RED.10="Smuggler Savant" _g.RED.11="Robber" _g.RED.12="Terrorist" _g.RED.13="Pirate" _g.RED.14="Infamous Pirate" _g.RED.15="Notorious Pirate" _g.RED.16="Dread Pirate" _g.RED.17="Galactic Scourge" _g.RED.18="Enemy of the State" _g.RED.19="Enemy of the People" _g.RED.20="Enemy of Humankind" _g.RED.21="Heinous Overlord" _g.RED.22="Prime Evil" _g.BLUE.0="11 21 7 10 6 20 3 2 14 16 15 4 8 23 13 5 19 17 1 12 18 22 9" _g.BLUE.1="Civilian" _g.BLUE.2="Private" /* match 2 */ _g.BLUE.3="Private 1st Class" /* match 1 */ _g.BLUE.4="Lance Corporal" _g.BLUE.5="Corporal" _g.BLUE.6="Sergeant" /* match 9 */ _g.BLUE.7="Staff Sergeant" _g.BLUE.8="Gunnery Sergeant" _g.BLUE.9="1st Sergeant" _g.BLUE.10="Sergeant Major" /* match 5 */ _g.BLUE.11="Warrant Officer" _g.BLUE.12="Chief Warrant Officer" _g.BLUE.13="Ensign" _g.BLUE.14="Lieutenant J.G." /* match 14 */ _g.BLUE.15="Lieutenant" /* match 13,15 */ _g.BLUE.16="Lieutenant Commander" /* match 14 */ _g.BLUE.17="Commander" _g.BLUE.18="Captain" _g.BLUE.19="Commodore" _g.BLUE.20="Rear Admiral" _g.BLUE.21="Vice Admiral" _g.BLUE.22="Admiral" _g.BLUE.23="Fleet Admiral" return /* Nuisance 3rd Class Nuisance 2nd Class Nuisance 1st Class Menace 3rd Class Menace 2nd Class Menace 1st Class Smuggler 3rd Class Smuggler 2nd Class Smuggler 1st Class Smuggler Savant Robber Terrorist Pirate Infamous Pirate Notorious Pirate Dread Pirate Galactic Scourge Enemy of the State Enemy of the People Enemy of Humankind Heinous Overlord Prime Evil Private Private 1st Class Lance Corporal Corporal Sergeant Staff Sergeant Gunnery Sergeant 1st Sergeant Sergeant Major Warrant Officer Chief Warrant Officer Ensign Lieutenant J.G. Lieutenant Lieutenant Commander Commander Captain Commodore Rear Admiral Vice Admiral Admiral Fleet Admiral */ /** _sendwait v.1 **/ _sendwait: procedure expose (globals) if \arg(1,"E") | \arg(2,"E") then call _error "missing parameter in _sendwait" call zocsend arg(1) rslt=zocwait(arg(2)) select when \arg(3,"E") | arg(3)="" then nop when lower(arg(3))="timeout" & rslt=640 then call _error "timeout" when lower(arg(3))="lastline" & rslt=640 then call _error "timeout" when lower(arg(3))="lastline" then rslt=_lastline() otherwise nop end /*select*/ return rslt /** _lastline v.3 **/ _lastline: procedure expose (globals) rslt=zoclastline() select when lower(arg(1))="raw" then nop when pos(d2c(7),rslt)>0 then rslt=translate(zocstring("REMOVE", rslt, d2c(7))," ",d2c(0)||d2c(10)) otherwise rslt=translate(rslt," ",d2c(0)||d2c(10)) end /*select*/ return rslt /** _fileexists v.3 **/ _fileexists: procedure expose (globals) if \arg(1,"E") then call _error "missing parameter in _fileexists" if stream(arg(1), "C", "QUERY EXISTS")="" then rslt=0; else rslt=1 return rslt